package com.example.flowerpcback.controller;

import com.example.flowerpcback.req.KnowledgeReq;
import com.example.flowerpcback.req.TagReq;
import com.example.flowerpcback.resp.CommonResp;
import com.example.flowerpcback.resp.KnowledgeResp;
import com.example.flowerpcback.resp.PageResp;
import com.example.flowerpcback.resp.TagResp;
import com.example.flowerpcback.services.KnowledgeService;
import com.example.flowerpcback.services.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "知识库接口")
@RestController //这是返回接口
@RequestMapping("/knowledge")
public class KnowledgeController {

    private static final Logger LOG = LoggerFactory.getLogger(KnowledgeController.class);

    @Resource
    private KnowledgeService knowledgeService;

    @ApiOperation("保存知识库（新增或编辑）")
    @PostMapping("/save")
    public CommonResp<KnowledgeResp> save(@Valid @RequestBody KnowledgeReq req){
        CommonResp resp= new CommonResp<>();
        KnowledgeResp res = knowledgeService.save(req);
        resp.setData(res);
        return  resp;
    }

    @ApiOperation("知识库列表")
    @GetMapping("/list")
    public CommonResp<PageResp<KnowledgeResp>> list(@Valid KnowledgeReq req){
        CommonResp<PageResp<KnowledgeResp>> resp= new CommonResp<>();
        PageResp<KnowledgeResp> res = knowledgeService.list(req);
        resp.setData(res);
        return  resp;
    }

    @ApiOperation("知识库列表")
    @GetMapping("/all")
    public CommonResp<List<KnowledgeResp>> all(@Valid KnowledgeReq req){
        CommonResp<List<KnowledgeResp>> resp= new CommonResp<>();
        List<KnowledgeResp> res = knowledgeService.all(req);
        resp.setData(res);
        return  resp;
    }

    @ApiOperation("删除知识库")
    @GetMapping("/delete")
    public CommonResp delete(@Valid KnowledgeReq req){
        CommonResp resp= new CommonResp<>();
        knowledgeService.delete(req);
        return  resp;
    }

}

